package org.karelun.rabbit.bridge.ui.action;

import java.util.Collection;

import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.edit.command.DeleteCommand;
import org.eclipse.emf.edit.command.RemoveCommand;
import org.eclipse.ui.IWorkbenchPart;
import org.karelun.rabbit.bridge.ITransactionEditingDomain;
import org.karelun.rabbit.bridge.ITransactionEditingDomainProvider;

public class RabbitDeleteAction extends RabbitCommandActionHandler{

	protected boolean removeAllReferences;
	
	public RabbitDeleteAction(ITransactionEditingDomain domain,boolean removeAllReferences) {
		super(domain,"Delete");
		this.removeAllReferences=removeAllReferences;
	}
	
	public RabbitDeleteAction(ITransactionEditingDomain domain){
		this(domain,false);
	}

	public RabbitDeleteAction(boolean removeAllReferences){
		this(null,removeAllReferences);
	}
	
	@Override
	protected Command createCommand(Collection<Object> selection) {
		return removeAllReferences ? DeleteCommand.create(editingDomain, selection) : RemoveCommand.create(editingDomain, selection);
	}
	
	public void setActiveWorkbenchPart(IWorkbenchPart workbenchPart){
		if(workbenchPart instanceof ITransactionEditingDomainProvider){
			editingDomain=((ITransactionEditingDomainProvider)workbenchPart).getTransactionEditingDomain();
		}
	}
}
